#include <iostream>
#include <numeric>
#include <vector>

using namespace std;

static int proper_divisor_sum(int num) {
    if (num < 2)
        return 0;

    vector<int> v;
    for (int i = 1; i < num; ++i) {
        if (num % i == 0)
            v.push_back(i);
    }

    return accumulate(v.begin(), v.end(), 0);
}

int main() {
    vector<int> v;
    for (int i = 0; i < 10000; ++i)
        v.push_back(proper_divisor_sum(i));

    int sum = 0;
    for (int i = 0; i < v.size(); ++i) {
        if (v[i] < v.size() && v[i] != i && v[v[i]] == i) {
	    cout << i << endl;
	    sum += i;
        }
    }
    cout << sum << endl; // 31626
}
